# Base image for HDS portal
FROM        ppc64le/centos:7.2
MAINTAINER  Andy Zhang <zch@cn.ibm.com>
ENV         container=docker
ENV         INST_DIR /var/setup
RUN         mkdir $INST_DIR
WORKDIR     $INST_DIR

# install cdsdk
ARG         FILESERVER=http://172.16.0.164:8080/base_image
ENV         FILESERVER ${FILESERVER}
ENV         INFORMIXDIR /opt/informix/
ENV         LD_LIBRARY_PATH $INFORMIXDIR/lib:$INFORMIXDIR/lib/esql:\
$INFORMIXDIR/lib/cli:$INFORMIXDIR/lib/c++:$INFORMIXDIR/lib/client:$INFORMIXDIR/lib/dmi
ADD         $FILESERVER/epel-release-7-5.noarch.rpm epel.rpm
ADD         $FILESERVER/clientsdk.tar clientsdk.tar
RUN         mkdir clientsdk && tar -xvf clientsdk.tar -C clientsdk && cd clientsdk \
            && ./installclientsdk -i silent -DLICENSE_ACCEPTED=TRUE -DUSER_INSTALL_DIR=$INFORMIXDIR
ENV	        INFORMIXSERVER  local_ifx
ENV	        INFORMIXSQLHOSTS $INFORMIXDIR/etc/sqlhosts.ifxserver
ENV	        INFORMIXCONTIME 15
COPY	    sqlhosts.ifxserver	$INFORMIXDIR/etc/

# Install epel and update yum
RUN         rpm -ivh epel.rpm \
	        && yum update -y && yum install -y python-pip python-devel.ppc64le httpd php mod_wsgi \
	        php-pdo php-devel libjpeg-devel postgresql-devel php-pecl-mongo
# Need to install fixed InformixDB because of hard coded checking in csdk version info
ADD         $FILESERVER/InformixDB-2.5.tar.gz InformixDB-2.5.tar.gz
# Not using informix django backend since there is some performance issue
#ADD 	    https://pypi.python.org/packages/e0/04/e043c001b36ed3c44b97d0e1279ec7e5c69092e1b95b203f4007241c4f69/django_informixdb-0.1.3-py2.py3-none-any.whl django_informixdb-0.1.3-py2.py3-none-any.whl
RUN 	    pip install InformixDB-2.5.tar.gz
#COPY        req.txt $INST_DIR/req.txt
#RUN         pip install -r req.txt  -i http://pypi.douban.com/simple --trusted-host pypi.douban.com

# Install mongodb enterprise tools
ADD         https://repo.mongodb.com/yum/redhat/7/mongodb-enterprise/3.2/ppc64le/RPMS/mongodb-enterprise-tools-3.2.8-1.el7.ppc64le.rpm mongodb-enterprise-tools-3.2.8-1.el7.ppc64le.rpm
RUN         yum install -y cyrus-sasl cyrus-sasl-plain cyrus-sasl-gssapi && rpm -ivh mongodb-enterprise-tools-3.2.8-1.el7.ppc64le.rpm && rm mongodb-enterprise-tools-3.2.8-1.el7.ppc64le.rpm 

# install clouddb
ADD         $FILESERVER/clouddb.tgz clouddb.tgz
RUN         mkdir /data && tar -xvf clouddb.tgz -C /data && [ -d /data/log ] || mkdir /data/log/ \
            && pip install -r /data/requirements.txt  -i http://pypi.douban.com/simple --trusted-host pypi.douban.com
RUN         /data/manage.py collectstatic --link --noinput
VOLUME      ["/data/", "/var/log/httpd/"]
WORKDIR     /data/
COPY        run_httpd.sh init.sh /
COPY        clouddb.conf    /etc/httpd/conf.d/
RUN         rm -fr $INST_DIR && chmod -v +x /*.sh && chown apache:apache $INFORMIXSQLHOSTS \
	        && chown -R apache:apache /data/
EXPOSE      80 443

ENTRYPOINT  ["/run_httpd.sh"]
